#include<bits/stdc++.h>
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define mid ((l+r)>>1)
#define File(xxx) freopen(xxx".in","r",stdin),freopen(xxx".out","w",stdout)
using namespace std;
namespace IO{
    char buff[1<<21],*p1=buff,*p2=buff;
    char getch(){
        return p1==p2&&(p2=((p1=buff)+fread(buff,1,1<<21,stdin)),p1==p2)?EOF:*p1++;
    }
    template<typename T>
    void read(T &x){
        char ch=getch();int fl=1;x=0;
        while(ch>'9'||ch<'0'){if(ch=='-')fl=-1;ch=getch();}
        while(ch<='9'&&ch>='0'){x=x*10+ch-48;ch=getch();}
        x*=fl;
    }
    template<typename T,typename ...Args>
    void read(T &x,Args& ...args){
        read(x);read(args...);
    }
    char obuf[1<<21],*p3=obuf;
    void putch(char ch){
        if(p3-obuf<(1<<21))*p3++=ch;
        else fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=ch;
    }
    void pc(const char *s){
    	while(*s)putch(*s),s++;
    }
    char ch[100];
    template<typename T>
    void write(T x){
        if(!x)return putch('0');
        if(x<0)putch('-'),x*=-1;
        int top=0;
        while(x)ch[++top]=x%10+48,x/=10;
        while(top)putch(ch[top]),top--;
    }
    template<typename T,typename ...Args>
    void write(T x,Args ...args){
        write(x),putch(' '),write(args...);
    }
    void flush(){fwrite(obuf,p3-obuf,1,stdout);p3=obuf;}
}
using namespace IO;
const int N=1205;
int n;
int son[N][2];
ll dep[N],dis[N][N];
vector<pair<int,int>>to[N];
void dfs1(int x,int fa){
	for(auto E:to[x]){
		int y=E.first,w=E.second;
		if(y==fa)continue;
		dep[y]=dep[x]+w;
		dfs1(y,x);
	}
}
void dfs2(int x,int fa,ll d,int id){
	dis[id][x]=d;
	for(auto E:to[x]){
		int y=E.first,w=E.second;
		if(y==fa)continue;
		dfs2(y,x,d+w,id);
	}
}
ll X;
int f[N][N];
int cmp(int x,int y){return (x<0||y<0)?max(x,y):(dep[x]<dep[y]?x:y);}
void dfs(int x){
	if(!son[x][0]){
		for(int i=1;i<=n;i++)
			if(dis[x][i]>X)f[x][i]=-1;
			else f[x][i]=x;
//		cerr<<x<<':';
//		for(int i=1;i<=n;i++)
//			cerr<<f[x][dfn[i]]<<' ';
//		cerr<<'\n';
		return;
	}
	dfs(son[x][0]),dfs(son[x][1]);
	for(int i=1;i<=n;i++){
		f[x][i]=-1;
		if(f[son[x][0]][i]>0)f[x][i]=cmp(f[x][i],f[son[x][1]][f[son[x][0]][i]]);
		if(f[son[x][1]][i]>0)f[x][i]=cmp(f[x][i],f[son[x][0]][f[son[x][1]][i]]);
	}
//	cerr<<x<<':';
//	for(int i=1;i<=n;i++)
//		cerr<<f[x][dfn[i]]<<' ';
//	cerr<<'\n';
}
bool check(){
	dfs(1);
	for(int i=1;i<=n;i++)
		if(f[1][i]>0)return 1;
	return 0;
}
signed main(){
	File("trip");
	read(n);
	for(int i=2;i<=n;i++){
		int x,y;
		read(x,y);
		if(!son[x][0])son[x][0]=i;
		else son[x][1]=i;
		to[x].push_back({i,y});
		to[i].push_back({x,y});
	}
	dfs1(1,0);
	for(int i=1;i<=n;i++)
		dfs2(i,0,0ll,i);
	ll l=0,r=1e12;
	while(l<r){
		X=mid;
		if(check())r=mid;
		else l=mid+1;
	}
	write(l);
	return flush(),0;
}
